import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.io.StreamConnection;


/**
 * @author Mathieu Maret
 *
 * A abstract class that is designed for deal with a connection create by a server.
 * Everytime a Client connect to the server the run() methode will be call and run in a new thread 
 */
public abstract class ServerConnectionDialer implements Runnable{
	private StreamConnection conn;
	private DataInputStream in;
	private DataOutputStream out;
	
	
	public void setConn(StreamConnection conn){
		this.conn = conn;
		try {
			in = conn.openDataInputStream();
			out = conn.openDataOutputStream();
		} catch (IOException e) {
			e.printStackTrace();
		}
		

		
	}
	public abstract void run();
	/**
	 * Close all the connection
	 */
	public void cleanup() {
		if(in != null){
			try {
				in.close();
			} catch (IOException e) {

				e.printStackTrace();
			}
		}
		if(out != null){
			try {
				out.close();
			} catch (IOException e) {

				e.printStackTrace();
			}
		}
		if (conn != null) {
			try {
				conn.close();
			} catch (IOException e) {

				e.printStackTrace();
			}
		}


	}
	public StreamConnection getConn() {
		return conn;
	}
	public DataInputStream getIn() {
		return in;
	}
	public DataOutputStream getOut() {
		return out;
	}
}



